package com.mc.servlet;

import com.mc.VO.ScoreVO;
import com.mc.bean.Jury;
import com.mc.bean.Student;
import com.mc.bean.Teacher;
import com.mc.service.ScoreVOService;
import com.mc.service.impl.ScoreVOServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Description 
 * @author wangcf
 * @date 2023/2/15 11:05
 * @version 1.0
 */
@WebServlet("/scorelist.action")
public class ScoreListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ScoreVOService scoreVOService=new ScoreVOServiceImpl();
        HttpSession session=req.getSession();
        Object obj=session.getAttribute("user");
        if(obj instanceof Teacher){
            Teacher teacher=(Teacher)obj;
            List<ScoreVO> scoreVOList=scoreVOService.findByTid(teacher.getTid());
            req.setAttribute("scorelist",scoreVOList);
            req.getRequestDispatcher("scorelist.jsp").forward(req,resp);
        }else if(obj instanceof Student){
            Student student=(Student)obj;
            List<ScoreVO> scoreVOList=scoreVOService.findBySid(student.getSid());
            System.out.println(scoreVOList);
            req.setAttribute("scorelist",scoreVOList);
            req.getRequestDispatcher("scorelist.jsp").forward(req,resp);
        }else if(obj instanceof Jury){
            Jury jury=(Jury)obj;
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
